package generics;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

//class  Chair{}
class Pair<T>{
	private T first;
	private T last;
	public Pair( T f, T l){
		first = f;
		last = l;
	}
	public void findMinAndMax( List<T> input){
		T smallest = input.get( 0 );
		// Find the smallest thing
		for( T s : input)
			if ( smallest.compareTo( s ) > 0)
				smallest = s;
		first = smallest;
		
		T biggest = input.get( 0 );
		// Find the biggest
		for( T s : input)
			if (biggest.compareTo( s ) < 0)
				biggest = s;
		last = biggest;
	}
	public String toString(){
		return "[" + first +", " + last +"]";
	}
}
/*
class Pair<T>{
	private T first;
	private T last;
	public Pair( T f, T l){
		first = f;
		last = l;
	}
	public void findMinAndMax( List<T> input){
		T smallest;
		// Find the smallest thing
		
		first = smallest;
		
		T biggest;
		// Find the biggest
		
		last = biggest;
	}
	public String toString(){
		return "[" + first +", " + last +"]";
	}
}
*/
public class Generics {

	public static void main(String[] args) {
		List<String> names = new ArrayList<String>();
		names.add("Tom");
		names.add("Jane");
		names.add("Agnes");
		names.add("James");	
//		Chair jacobschair = new Chair();
//		names.add( jacobschair );
		for (String o : names )
			System.out.println( o );
		Pair<String> p = new Pair<String>( names.get(0), names.get( names.size() - 1));
		System.out.println("First and last are " + p);

		p.findMinAndMax( names );
		System.out.println("Smallest and biggest are " + p);
		
		List<Integer> numbers = new ArrayList<Integer>();
		numbers.add(5);
		numbers.add(7);
		numbers.add(53);
		numbers.add(-90);	
		for (Integer o : numbers )
			System.out.println( o );
		Pair<Integer> ip = new Pair<Integer>(numbers.get(0), numbers.get( names.size() - 1));
		System.out.println("First and last are " + ip);

	}
}
